#!/usr/bin/env bash

export PYTHONPATH=`pwd`

start () {
    nohup python3 source/QuotaCalc/main.py > /dev/null 2>&1 &
    nohup python3 source/StrategyCombin/main.py > /dev/null 2>&1 &
    nohup python3 source/Simulation/main.py > /dev/null 2>&1 &
    nohup python3 source/FrontEnd/manage.py runserver 0.0.0.0:8000 > /dev/null 2>&1 &
}

stop () {
    task=("QuotaCalc" "StrategyCombin" "FrontEnd" "Simulation")
    for data in ${task[@]}
    do
        ps aux | grep ${data} | grep -v grep | awk '{print $2}' | xargs kill -9
    done
    echo "all clear."
}

if [ -n "$1" ] && [ $1 == "start" ]
then
    start
elif [ -n "$1" ] && [ $1 == "stop" ]
then
    stop
elif [ -n "$1" ] && [ $1 == "restart" ]
then
    stop
    start
else
    echo "请输入参数: start, stop, restart"
fi
